// api/user_api/wx_login.go
package user_api

import (
	"github.com/gin-gonic/gin"
	"muziai-server/service/user_service"
	"muziai-server/utils/jwts"
	"muziai-server/utils/res"
)

type UpdateUserInfoRequest struct {
	Nickname *string `json:"nickname"`
	Avatar   *string `json:"avatar"`
}

func (u UserApi) UpdateUserInfoView(c *gin.Context) {
	var cr UpdateUserInfoRequest
	err := c.ShouldBindJSON(&cr)
	if err != nil {
		res.FailWithError(c, err)
		return
	}
	_claims, _ := c.Get("claims")
	claims := _claims.(*jwts.Claims)

	_, err = u.UserService.UserUpdate(claims.UserID, user_service.UserUpdateRequest{
		Nickname: cr.Nickname,
		Avatar:   cr.Avatar,
	})
	if err != nil {
		res.FailWithError(c, err)
		return
	}
	res.OkWithMsg(c, "用户信息更新成功")
}
